<%@ page contentType="text/html;charset=GBK" %>
<%@ page import="java.util.*" %>
<%@ page import="com.ionglobal.db.*" %>
<%@ page import="com.ionglobal.lib.*" %>
<%@ page import="com.ionglobal.cms.*" %>
<%@ page import="com.ionglobal.misc.*" %>

<%@ include file="init_include.jsp" %>
<HTML>
<HEAD>
<style>
BODY {font-size:9pt;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=<%=Language.getHTMLLanguageStr()%>">

<script language="javascript">

var	ns4 = (document.layers)? true:false;
var	ie4 = (document.all)? true:false;

var baseX=5;
var baseY=25;

var curRow=0;
var itemHeight=20;
var colWidtht=24;

var treeString='';
var ladderObject_array= new Array();
var itemObject_array = new Array(); 	

plusSrc	='<img src="./images/plus.gif" BORDER=0 ';    
minusSrc='<img src="./images/minus.gif" BORDER=0 ';   
hlineSrc='<img src="./images/hline.gif">';
vlineSrc='<img src="./images/vline.gif" ';
btmSrc	='<img src="./images/btm.gif">';
midSrc	='<img src="./images/mid.gif">';
topSrc	='<img src="./images/top.gif">';

vLineImage=new Image();
vLineImage.src="./images/vline.gif";

hLineImage=new Image();
hLineImage.src="./images/hline.gif";

plusImage=new Image();
plusImage.src="./images/plus.gif";

minusImage=new Image();
minusImage.src="./images/minus.gif";

btmImage=new Image();
btmImage.src="./images/btm.gif";

midImage=new Image();
midImage.src="./images/mid.gif";

topImage=new Image();
topImage.src="./images/top.gif";


function ladderObject(id,index,layer,x,y,isExpand,image)
{
	this.id=id;
	this.index=index;
	this.x=x;
	this.y=y;
	this.layer=layer;
	this.isExpand=isExpand;
	this.image=image;
}
		 
function itemObject(id,name,index,layer,isLeaf,isLastChild,isExpand,haveUrl,linkUrl)
{
	this.id=id;
	this.name=name;
	this.index=index;
	this.layer=layer;
	this.isLeaf=isLeaf;
	this.isLastChild=isLastChild;
	this.isExpand=isExpand
	this.x=0; 
	this.y=0;//pic position
	this.image=0;
	this.haveUrl=haveUrl;
	this.linkUrl=linkUrl;
}

function ladderClone(ladderItem)
{
	a=new ladderObject(0,0,0,0,0,true,midImage);
	a.id=ladderItem.id;
	a.index=ladderItem.index;
	a.x=ladderItem.x;
	a.y=ladderItem.y;
	a.isExpand=ladderItem.isExpand;
	a.layer=ladderItem.layer;
	a.image=ladderItem.image;
	return a;
}
<%
	Vector vc;
	String str="";
	ItemData ca;
	
	Sysop sysop=(Sysop)session.getAttribute("sysop");
	if ( sysop==null)	{
		response.sendRedirect("logout.jsp");
	 	return;
	}
			
//	long t1=System.currentTimeMillis();	
	vc=Tree.getFullTree(dbi,0,sysop.getId(),session,"tree");
//	long t2=System.currentTimeMillis()-t1;
		
//	out.print(t2);
	if(vc.size()<1)
		out.print("//No Item Found in database!");
	for (int i=1;i<vc.size();i++)	{		
		ca=(ItemData)vc.get(i);
		str="itemObject_array["+String.valueOf(i-1)+"]=new itemObject(";
		str+=ca.id+",'"+Utilities.strReplace(ca.name,"'","\\'")+"',"+ca.index+","+ca.layer+","+ca.isLeaf+","+ca.isLastChild+","+"false,"+ca.haveLink+",'"+ca.linkUrl +"');" ;
		out.println(str);
	}		
%>
</script>


<script language="javascript">

function isIgnoreItem(item)
{	
	var i;
	for (i=0;i<item.layer-1;i++)
	{
		if (!ladderObject_array[i].isExpand)
		return true;
	}
	return false;
}

function setLadderArray(item,i)
{
	if (ladderObject_array[i])
	{
		ladderObject_array[i].id=item.id;
		ladderObject_array[i].index=item.index;
		ladderObject_array[i].x=item.x;
		ladderObject_array[i].y=item.y;
		ladderObject_array[i].isExpand=item.isExpand;
		ladderObject_array[i].image=item.image;
		
	}
	else
	ladderObject_array[i]=new ladderObject(item.id,item.index,item.layer,item.x,item.y,item.isExpand,item.image);
}

function getPicSrc(item)
{
	var clickStr='';
	treeString='';
	if (item.isLeaf)
	{
		if (item.layer==1)
		{ 
			if (item.index==1){item.image=topImage;return topSrc;}
			else
			{
				if (item.isLastChild)
				{item.image=btmImage;return btmSrc;}
				else
				{item.image=midImage;return midSrc;}
				
			}		
		
		}
		else
		{
			if (item.isLastChild) { item.image=btmImage;return btmSrc;}
			else
			{item.image=midImage;return midSrc;}
		}
	}else
	{
		if (item.isExpand)
		{	
			clickStr='<a href="#" >'+minusSrc+'onClick="refresh('+item.index+')"></a>'+ hlineSrc;
			//clickStr=minusSrc+'onClick="refresh('+item.index+')">'+ hlineSrc;
			item.image=minusImage;
			return clickStr;
		}	 
		else
		{	
			clickStr='<a href="#" >'+plusSrc+'onClick="refresh('+item.index+')"></a>'+ hlineSrc;		
			//clickStr=plusSrc+'onClick="refresh('+item.index+')">'+ hlineSrc;		
			item.image=plusImage;
			return (clickStr);
		}
	}
}

function drawItem(item)
{	
	tmpStr=getPicSrc(item);
	var tmpX=item.x-item.image.width/2;
	
	tmpStr ='<span id='+item.id+' style="position:absolute;left:'+tmpX+ '; top:'+item.y+';height:'+itemHeight+'">'+tmpStr;
	tmpStr+='<span style="position:absolute">';
	
	if (item.haveUrl)
	{
		tmpStr+='<a href="'+ item.linkUrl + '" target="right">';
		tmpStr+='<nobr>'+item.name+'</nobr>';
		tmpStr+='</a></span>';	
	}else
	{
		tmpStr+='<nobr>'+item.name+'</nobr>';
		tmpStr+='</a></span>';	
	}
	tmpStr+='</span>';
	return tmpStr;
}

function viewDraw(ladderA,itemB)
{
	var str='';
	str ='ladderA[x='+ladderA.x+' y='+ladderA.y+' height:'+ladderA.image.height+' id:'+ladderA.id+'\n';
	str+='  itemB[x='+itemB.x  +' y='+  itemB.y+' height:'+  itemB.image.height+' name:'+  itemB.name+'\n'; 	
	return str;
}
	

function drawVLine(ladderA,itemB)
{
	var x,tmpY;
	var len;
	var lineStr='';
		
	tmpY=ladderA.y+ladderA.image.height;
	
	//tmpY=ladderA.y+ladderA.image.height;
	//tmpY=ladderA.y+ladderA.image.height+vLineImage.height/2;
	
	
	//x=ladderA.x+vLineImage.width/2;
	x=ladderA.x-vLineImage.width/2;
	
	len=itemB.y-tmpY;
	lineStr+='<span id='+tmpY+' style="position:absolute;left:'+x+ '; top:'+tmpY+'">'+vlineSrc;
	lineStr+=' width="'+vLineImage.width+'" height="'+len +'"></span>';

	return lineStr;	
}


function getTreeSrc()
{
	var k;
	var oldLadder;
	for( k=0;k<itemObject_array.length;k++)
	{	
	
		curItem=itemObject_array[k];
		
		if ( (curItem.layer>1) && ( isIgnoreItem(curItem) ) )
		{	
			continue;
		}
			
		if (k==0) 
		{	
			curItem.x=baseX;
			curItem.y=baseY;
			treeString+=drawItem(curItem);
			setLadderArray(curItem,curItem.layer-1);
			curRow++;
			//window.alert('index='+curItem.index+' name:'+curItem.name+' height='+curItem.image.height);
		}else
		{
			curRow++;
			curItem.x=baseX + (curItem.layer-1)*colWidtht;
			curItem.y=baseY + (curRow-1)*itemHeight;
			treeString+=drawItem(curItem);
			
			
			if ( curItem.layer>itemObject_array[k-1].layer)
			{	
				setLadderArray(curItem,curItem.layer-1);
				//window.alert('index='+curItem.index+' name:'+curItem.name+' height='+curItem.image.height);
				continue;
			}	
			
			oldLadder=ladderClone(ladderObject_array[curItem.layer-1]);
			treeString+= drawVLine(oldLadder,curItem);
			setLadderArray(curItem,curItem.layer-1);			
		}
	}
}

function paintMenu(newCode) {
	if (navigator.appName=="Netscape") {
		A = document.layers["tree"];
		A.document.open("text/html","replace");
		A.document.write(newCode);
		A.document.close();
	}
	else {
		tree.innerHTML=newCode;
	}
}

function refresh(which)
{	
	curRow=0;
	treeString='';
	itemObject_array[which-1].isExpand=!itemObject_array[which-1].isExpand;
	getTreeSrc();
	//window.alert(treeString);
	paintMenu(treeString);
}


function init()
{
	getTreeSrc();
	paintMenu(treeString);
}
</SCRIPT>
</HEAD>
<body>
BMS <%=Language.getNameByCode("sys.Refresh","Refresh")%>&nbsp;<a href="#"><img border="0" src="./images/refresh.GIF" onClick="self.location.reload();" align="absbottom" alt="<%=Language.getNameByCode("sys.Refresh","Refresh")%>"></a> 
<a href="logout.jsp?LoginId=<%=sysop.getLoginId()%>"> Logout</a>
<hr>

<SCRIPT LANGUAGE="JavaScript">
document.write('<SPAN ID=tree STYLE="position: absolute; left:'+baseX+'; top:'+baseY+'; width:100%; height:100%"> </SPAN>');
init();
//window.onload=init();
</script>
</BODY>
</HTML>
<%@ include file="init_free.jsp" %>

